import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

/**
 * tester class for the credit card class.
 * @author Kyle Scharnhorst/Kristopher Gooding
 * @version 04/25/2014
 */
public class CreditCardTest {

	/**
	 * Credit card made with first constructor.
	 */
	private CreditCard my_first_card;

	/**
	 * Credit card made with second constructor.
	 */
	private CreditCard my_second_card;

	/**
	 * Delta, the difference accepted when doing an equals assertion on
	 * numerical values.
	 */
	private static int DELTA = 0;

	/**
	 * default credit limit
	 */
	private static int DEFAULT_CREDIT_LIMIT = 2500;

	/**
	 * Credit limit for use in the second card constructor.
	 */
	private int CREDIT_LIMIT = 200;

	/**
	 * First pay amount.
	 */
	private static double PAY_AMOUNT = 210;

	/**
	 * Second pay amount.
	 */
	private static double ANOTHER_PAY_AMOUNT = 10;

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		my_first_card = new CreditCard("name", "street", "town", "zipcode",
				"country");
		my_second_card = new CreditCard("name", "street", "town", "zipcode",
				"country", CREDIT_LIMIT);
	}

	/**
	 * Test method for
	 * {@link CreditCard#CreditCard(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)}
	 * .
	 */
	@Test
	public void testCreditCardStringStringStringStringString() {
		assertTrue(my_first_card.getMember().getName().equals("name"));
		assertTrue(my_first_card.getMember().getAddress().getStreet()
				.equals("street"));
		assertTrue(my_first_card.getMember().getAddress().getTown()
				.equals("town"));
		assertTrue(my_first_card.getMember().getAddress().getZipCode()
				.equals("zipcode"));
		assertTrue(my_first_card.getMember().getAddress().getCountry()
				.equals("country"));
		assertEquals(my_first_card.getLimit(), DEFAULT_CREDIT_LIMIT, DELTA);
		assertEquals(my_first_card.getBalance(), 0, DELTA); // default balance
																// is 0.
	}

	/**
	 * Test method for
	 * {@link CreditCard#CreditCard(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, double)}
	 * .
	 */
	@Test
	public void testCreditCardStringStringStringStringStringDouble() {
		assertTrue(my_second_card.getMember().getName().equals("name"));
		assertTrue(my_second_card.getMember().getAddress().getStreet()
				.equals("street"));
		assertTrue(my_second_card.getMember().getAddress().getTown()
				.equals("town"));
		assertTrue(my_second_card.getMember().getAddress().getZipCode()
				.equals("zipcode"));
		assertTrue(my_second_card.getMember().getAddress().getCountry()
				.equals("country"));
		assertEquals(my_second_card.getLimit(), CREDIT_LIMIT, DELTA);
		assertEquals(my_second_card.getBalance(), 0, DELTA);
	}

	/**
	 * Test method for {@link CreditCard#pay(double)}.
	 */
	@Test
	public void testPay() {
		// default balance is 0.
		my_second_card.pay(ANOTHER_PAY_AMOUNT);
		assertEquals(my_second_card.getBalance(), 0, DELTA);
		my_second_card.pay(PAY_AMOUNT);
		assertEquals(my_second_card.getBalance(), -PAY_AMOUNT, DELTA);
	}

}
